/* This file was created by Nokia Developer's Suite for J2ME(TM) */

import java.util.Enumeration;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;

import localization.Language;
import localization.LocalizationManager;

public class LoaderScreen extends List
{
	private final static Language language = LocalizationManager.getCurrentLanguageFromInstance();
	
    public static final Command m_back= new Command( language.getBackText(), Command.BACK, 0);
    public static final int LOAD_STATE  = 1;
    public static final int DELETE_STATE= 3;
    
    public final int m_iState;
    
    private Storage storage;
    
   
    //konstruuje liste planow w pamieci komorki w formie menu
    public LoaderScreen( String label, int state, Scheduler midlet ) //wymaga podania ktora komende ma realizowac
    {
        super( label, Choice.IMPLICIT );
        addCommand( m_back );
        setCommandListener( midlet );
        m_iState = state;
    
        storage = Storage.getInstance();
        
        recreateList();
    }
    
    public byte[] readTable( int num ) //odczytuje bajty z danego pola w pamieci trwalej
    {
        byte[] wynik= null;
        try
        {
            wynik = storage.getTimeTable( num );
        }catch( RecordStoreException e ){}
        //jesli nic tam nie bylo to zwracany jest wynik ustawiony na null
        
        return wynik;
    }
      
    //usuwa dane pole w pamieci trwalej
    public void deleteTable( int num ) throws RecordStoreException 
    {
        storage.deleteTimeTable( num );
    }
    
    private void recreateList()
    {
        while( size() > 0)
            this.delete( 0 );
        
        Enumeration e = storage.getNamesEnumeration();
        while( e.hasMoreElements() )
            this.append( (String)e.nextElement(), null );
    }
}